/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.tintuna.cca.spreadsheetview;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.openide.awt.StatusDisplayer;
import org.openide.util.Lookup;
import org.tintuna.cca.dao.SpreadsheetReader;
import org.tintuna.cca.data.Spreadsheet;
import org.tintuna.cca.node.SpreadsheetNode;

public final class OpenSpreadsheetView implements ActionListener {

    public void actionPerformed(ActionEvent e) {
        SpreadsheetReader spreadsheetreader = getSpreadSheetReader();
        StatusDisplayer.getDefault().setStatusText("Open Spreadsheet View - "+spreadsheetreader.toString());
        SpreadsheetNode spreadsheetnode = new SpreadsheetNode(new Spreadsheet(spreadsheetreader));
        SpreadsheetViewTopComponent spreadsheetViewTopComponent = new SpreadsheetViewTopComponent(spreadsheetnode);
        spreadsheetViewTopComponent.open();
        spreadsheetViewTopComponent.requestActive();
    }

    private SpreadsheetReader getSpreadSheetReader() {
        Collection<? extends SpreadsheetReader> ssrs;

        ssrs = Lookup.getDefault().lookupAll(SpreadsheetReader.class);
        return ssrs == null ? null : ssrs.iterator().next();
    }
}
